import Vue from 'vue'
import App from './App.vue'
import router from './router'

import store from './store'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/index.css'

import {initMenus} from './utils/menus'

//网络请求axios相关插件
import {postKeyValueRequest} from './utils/api'
import {postRequset} from './utils/api'
import {putRequset} from './utils/api'
import {getRequset} from './utils/api'
import {deleteRequset} from './utils/api'

Vue.prototype.postKeyValueRequest = postKeyValueRequest
Vue.prototype.postRequset = postRequset
Vue.prototype.putRequset = putRequset
Vue.prototype.getRequset = getRequset
Vue.prototype.deleteRequset = deleteRequset

Vue.config.productionTip = false

Vue.use(ElementUI);

router.beforeEach((to, from, next) => {
  if(to.path == '/') {
    // console.log("if(to.path == '/')",to,from);
    next();
  }else {
    if(window.sessionStorage.getItem("user")) {
      initMenus(router,store);
      next();
    }else {
      // console.log("else",to,from);
      next("/?redirect=" + to.path);
    }
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
